package com.demo.salary.transactionimplementation;

import com.demo.salary.abstracttransactions.ChangeAffiliationTransaction;
import com.demo.salary.payrolldomain.Affiliation;
import com.demo.salary.payrolldomain.Employee;
import com.demo.salary.payrollimplementation.NoAffiliation;
import com.demo.salary.payrolldatabase.PayrollDatabase;
import com.demo.salary.payrollimplementation.UnionAffiliation;

public class ChangeUnaffiliatedTransaction extends ChangeAffiliationTransaction {


    public ChangeUnaffiliatedTransaction(int empId) {
        super(empId);
    }

    @Override
    Affiliation getAffiliation() {
        return new NoAffiliation();
    }

    @Override
    void recordMembership(Employee employee) {

        Affiliation affiliation = employee.getAffiliation();
        if (affiliation instanceof UnionAffiliation){
            UnionAffiliation ua = (UnionAffiliation) affiliation;
            PayrollDatabase.removeUnionMember(ua.getMemberId());
        }

    }
}
